package cmich.cps.scheduler;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.logging.Level;

import cmich.cps.scheduler.gui.Frame;
import cmich.cps.scheduler.gui.Prompts;

/**
 * The Class Main.
 * 
 * @author Jonathan Kissinger <kissi1j@cmich.edu>
 */
public class Main {

	/**
	 * The main method.
	 *
	 * @param args the arguments; unused
	 */
	public static void main(String[] args) {
		File dir = getDir();
		MyLogger.setup(Level.FINEST, Level.CONFIG, dir);
		SchedulingSystem sys = SchedulingSystem.getInstance();
		Prompts prompts = Prompts.getInstance();
		sys.init();
		prompts.init();
		Frame frame = Frame.getInstance();
		DatabaseServer.setup(false, dir);
		sys.loadDatabase();
		frame.populateWindow();
	}

	private static File getDir() {
		File dir = null;
		try {
			String location = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
			String decodedLocation = URLDecoder.decode(location, "UTF-8");
			dir = new File(decodedLocation).getParentFile();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return dir;
	}
}
